<!-- HTML header for doxygen 1.9.1-->
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <meta name="generator" content="Doxygen 1.9.4" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>NumCpp: Brent.hpp Source File</title>
    <link href="tabs.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="dynsections.js"></script>
    <link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
    <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="doxygen.css" rel="stylesheet" type="text/css" />
    <link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="doxygen-awesome-sidebar-only-darkmode-toggle.css" rel="stylesheet" type="text/css"/>
    <!-- ... other metadata & script includes ... -->
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeDarkModeToggle.init()
    </script>
    <script type="text/javascript"
        src="../doxygen-awesome-css/doxygen-awesome-fragment-copy-button.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeFragmentCopyButton.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-paragraph-link.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeParagraphLink.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-interactive-toc.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeInteractiveToc.init()
    </script>
</head>
<body>
    <div id="top">
        <!-- do not remove this div, it is closed by doxygen! -->
        <div id="titlearea">
            <table cellspacing="0" cellpadding="0">
                <tbody>
                    <tr style="height: 56px;">
                        <td id="projectlogo"><img alt="Logo" src="NumCppLogoDoxygen.png" /></td>
                        <td id="projectalign" style="padding-left: 0.5em;">
                            <div id="projectname">NumCpp
                                &#160;<span id="projectnumber">2.12.1</span>
                            </div>
                            <div id="projectbrief">A Templatized Header Only C++ Implementation of the Python NumPy Library</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- end header part --><!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('_brent_8hpp_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">Brent.hpp</div></div>
</div><!--header-->
<div class="contents">
<a href="_brent_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span><span class="preprocessor">#pragma once</span></div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span> </div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span><span class="preprocessor">#include &lt;functional&gt;</span></div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span><span class="preprocessor">#include &lt;utility&gt;</span></div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span> </div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span><span class="preprocessor">#include &quot;<a class="code" href="_dtype_info_8hpp.html">NumCpp/Core/DtypeInfo.hpp</a>&quot;</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><span class="preprocessor">#include &quot;<a class="code" href="_types_8hpp.html">NumCpp/Core/Types.hpp</a>&quot;</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span><span class="preprocessor">#include &quot;<a class="code" href="_iteration_8hpp.html">NumCpp/Roots/Iteration.hpp</a>&quot;</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span><span class="preprocessor">#include &quot;<a class="code" href="essentially_equal_8hpp.html">NumCpp/Utils/essentiallyEqual.hpp</a>&quot;</span></div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span> </div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespacenc_1_1roots.html">nc::roots</a></div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>{</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>    <span class="comment">//================================================================================</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>    <span class="comment">// Class Description:</span></div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html">   50</a></span><span class="comment"></span>    <span class="keyword">class </span><a class="code hl_class" href="classnc_1_1roots_1_1_brent.html">Brent</a> : <span class="keyword">public</span> <a class="code hl_class" href="classnc_1_1roots_1_1_iteration.html">Iteration</a></div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>    {</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>    <span class="keyword">public</span>:</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">   60</a></span><span class="comment"></span>        <a class="code hl_function" href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">Brent</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> epsilon, std::function&lt;<span class="keywordtype">double</span>(<span class="keywordtype">double</span>)&gt; <a class="code hl_function" href="namespacenc_1_1random_1_1detail.html#af5bfd54c6d5d0ad7e16e6e532b0dfb2e">f</a>) noexcept :</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>            <a class="code hl_function" href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">Iteration</a>(epsilon),</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>            f_(std::move(<a class="code hl_function" href="namespacenc_1_1random_1_1detail.html#af5bfd54c6d5d0ad7e16e6e532b0dfb2e">f</a>))</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>        {</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>        }</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span> </div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">   74</a></span><span class="comment"></span>        <a class="code hl_function" href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">Brent</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> epsilon, <span class="keyword">const</span> <a class="code hl_typedef" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">uint32</a> maxNumIterations, std::function&lt;<span class="keywordtype">double</span>(<span class="keywordtype">double</span>)&gt; <a class="code hl_function" href="namespacenc_1_1random_1_1detail.html#af5bfd54c6d5d0ad7e16e6e532b0dfb2e">f</a>) noexcept :</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>            <a class="code hl_function" href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">Iteration</a>(epsilon, maxNumIterations),</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>            f_(std::move(<a class="code hl_function" href="namespacenc_1_1random_1_1detail.html#af5bfd54c6d5d0ad7e16e6e532b0dfb2e">f</a>))</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>        {</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>        }</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span> </div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#ade76ad260d82314f284ebacf885f6884">   84</a></span><span class="comment"></span>        <a class="code hl_function" href="classnc_1_1roots_1_1_brent.html#ade76ad260d82314f284ebacf885f6884">~Brent</a>() <span class="keyword">override</span> = <span class="keywordflow">default</span>;</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"><a class="line" href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">   94</a></span><span class="comment"></span>        <span class="keywordtype">double</span> <a class="code hl_function" href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">solve</a>(<span class="keywordtype">double</span> a, <span class="keywordtype">double</span> b)</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>        {</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>            <a class="code hl_function" href="classnc_1_1roots_1_1_iteration.html#a85e79a4794bc3a6ac6bc3564956737a2">resetNumberOfIterations</a>();</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span> </div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>            <span class="keywordtype">double</span> fa = f_(a);</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>            <span class="keywordtype">double</span> fb = f_(b);</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span> </div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>            checkAndFixAlgorithmCriteria(a, b, fa, fb);</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span> </div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>            <span class="keywordtype">double</span> lastB        = a; <span class="comment">// b_{k-1}</span></div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>            <span class="keywordtype">double</span> lastFb       = fa;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>            <span class="keywordtype">double</span> s            = <a class="code hl_function" href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">DtypeInfo&lt;double&gt;::max</a>();</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>            <span class="keywordtype">double</span> fs           = <a class="code hl_function" href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">DtypeInfo&lt;double&gt;::max</a>();</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>            <span class="keywordtype">double</span> penultimateB = a; <span class="comment">// b_{k-2}</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span> </div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>            <span class="keywordtype">bool</span> bisection = <span class="keyword">true</span>;</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>            <span class="keywordflow">while</span> (std::fabs(fb) &gt; <a class="code hl_variable" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> &amp;&amp; std::fabs(fs) &gt; <a class="code hl_variable" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> &amp;&amp; std::fabs(b - a) &gt; <a class="code hl_variable" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a>)</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>            {</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>                <span class="keywordflow">if</span> (useInverseQuadraticInterpolation(fa, fb, lastFb))</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>                {</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>                    s = calculateInverseQuadraticInterpolation(a, b, lastB, fa, fb, lastFb);</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>                }</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>                <span class="keywordflow">else</span></div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>                {</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>                    s = calculateSecant(a, b, fa, fb);</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>                }</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span> </div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>                <span class="keywordflow">if</span> (useBisection(bisection, b, lastB, penultimateB, s))</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>                {</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>                    s         = calculateBisection(a, b);</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>                    bisection = <span class="keyword">true</span>;</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>                }</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>                <span class="keywordflow">else</span></div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>                {</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>                    bisection = <span class="keyword">false</span>;</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>                }</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span> </div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>                fs           = f_(s);</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>                penultimateB = lastB;</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>                lastB        = b;</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span> </div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>                <span class="keywordflow">if</span> (fa * fs &lt; 0)</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>                {</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>                    b = s;</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>                }</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>                <span class="keywordflow">else</span></div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>                {</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>                    a = s;</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>                }</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span> </div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>                fa     = f_(a);</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>                lastFb = fb;</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>                fb     = f_(b);</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>                checkAndFixAlgorithmCriteria(a, b, fa, fb);</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>                <a class="code hl_function" href="classnc_1_1roots_1_1_iteration.html#ad0262a1a694e734ebc154c77f010bcff">incrementNumberOfIterations</a>();</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>            }</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span> </div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span>            <span class="keywordflow">return</span> fb &lt; fs ? b : s;</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>        }</div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span> </div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno">  155</span>    <span class="keyword">private</span>:</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno">  156</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>        <span class="keyword">const</span> std::function&lt;double(<span class="keywordtype">double</span>)&gt; f_;</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span> </div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span><span class="comment"></span>        <span class="keyword">static</span> <span class="keywordtype">double</span> calculateBisection(<span class="keyword">const</span> <span class="keywordtype">double</span> a, <span class="keyword">const</span> <span class="keywordtype">double</span> b) <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno">  168</span>        {</div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno">  169</span>            <span class="keywordflow">return</span> 0.5 * (a + b);</div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>        }</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span> </div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno">  172</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno">  173</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span><span class="comment"></span>        <span class="keyword">static</span> <span class="keywordtype">double</span> calculateSecant(<span class="keyword">const</span> <span class="keywordtype">double</span> a, <span class="keyword">const</span> <span class="keywordtype">double</span> b, <span class="keyword">const</span> <span class="keywordtype">double</span> fa, <span class="keyword">const</span> <span class="keywordtype">double</span> fb) <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span>        {</div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno">  184</span>            <span class="comment">// No need to check division by 0, in this case the method returns NAN which is taken care by</span></div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno">  185</span>            <span class="comment">// useSecantMethod method</span></div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno">  186</span>            <span class="keywordflow">return</span> b - fb * (b - a) / (fb - fa);</div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno">  187</span>        }</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno">  188</span> </div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno">  189</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno">  190</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno">  201</span><span class="comment"></span>        <span class="keyword">static</span> <span class="keywordtype">double</span> calculateInverseQuadraticInterpolation(<span class="keyword">const</span> <span class="keywordtype">double</span> a,</div>
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno">  202</span>                                                             <span class="keyword">const</span> <span class="keywordtype">double</span> b,</div>
<div class="line"><a id="l00203" name="l00203"></a><span class="lineno">  203</span>                                                             <span class="keyword">const</span> <span class="keywordtype">double</span> lastB,</div>
<div class="line"><a id="l00204" name="l00204"></a><span class="lineno">  204</span>                                                             <span class="keyword">const</span> <span class="keywordtype">double</span> fa,</div>
<div class="line"><a id="l00205" name="l00205"></a><span class="lineno">  205</span>                                                             <span class="keyword">const</span> <span class="keywordtype">double</span> fb,</div>
<div class="line"><a id="l00206" name="l00206"></a><span class="lineno">  206</span>                                                             <span class="keyword">const</span> <span class="keywordtype">double</span> lastFb) <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno">  207</span>        {</div>
<div class="line"><a id="l00208" name="l00208"></a><span class="lineno">  208</span>            <span class="keywordflow">return</span> a * fb * lastFb / ((fa - fb) * (fa - lastFb)) + b * fa * lastFb / ((fb - fa) * (fb - lastFb)) +</div>
<div class="line"><a id="l00209" name="l00209"></a><span class="lineno">  209</span>                   lastB * fa * fb / ((lastFb - fa) * (lastFb - fb));</div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno">  210</span>        }</div>
<div class="line"><a id="l00211" name="l00211"></a><span class="lineno">  211</span> </div>
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno">  212</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno">  213</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno">  221</span><span class="comment"></span>        <span class="keyword">static</span> <span class="keywordtype">bool</span> useInverseQuadraticInterpolation(<span class="keyword">const</span> <span class="keywordtype">double</span> fa, <span class="keyword">const</span> <span class="keywordtype">double</span> fb, <span class="keyword">const</span> <span class="keywordtype">double</span> lastFb) <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno">  222</span>        {</div>
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno">  223</span>            <span class="keywordflow">return</span> !<a class="code hl_function" href="namespacenc_1_1utils.html#a963b90e7c9a3b057a924298750ddf74c">utils::essentiallyEqual</a>(fa, lastFb) &amp;&amp; <a class="code hl_function" href="namespacenc_1_1utils.html#a963b90e7c9a3b057a924298750ddf74c">utils::essentiallyEqual</a>(fb, lastFb);</div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno">  224</span>        }</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno">  225</span> </div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno">  226</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno">  227</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno">  235</span><span class="comment"></span>        <span class="keyword">static</span> <span class="keywordtype">void</span> checkAndFixAlgorithmCriteria(<span class="keywordtype">double</span> &amp;a, <span class="keywordtype">double</span> &amp;b, <span class="keywordtype">double</span> &amp;fa, <span class="keywordtype">double</span> &amp;fb) <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno">  236</span>        {</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno">  237</span>            <span class="comment">// Algorithm works in range [a,b] if criteria f(a)*f(b) &lt; 0 and f(a) &gt; f(b) is fulfilled</span></div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno">  238</span>            <span class="keywordflow">if</span> (std::fabs(fa) &lt; std::fabs(fb))</div>
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno">  239</span>            {</div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno">  240</span>                <a class="code hl_function" href="namespacenc.html#a39da0502565b913855379ea1439047e1">std::swap</a>(a, b);</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno">  241</span>                <a class="code hl_function" href="namespacenc.html#a39da0502565b913855379ea1439047e1">std::swap</a>(fa, fb);</div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno">  242</span>            }</div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno">  243</span>        }</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno">  244</span> </div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno">  245</span>        <span class="comment">//============================================================================</span></div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno">  246</span>        <span class="comment">// Method Description:</span></div>
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno">  256</span><span class="comment"></span>        [[nodiscard]] <span class="keywordtype">bool</span> useBisection(<span class="keyword">const</span> <span class="keywordtype">bool</span>   bisection,</div>
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno">  257</span>                                        <span class="keyword">const</span> <span class="keywordtype">double</span> b,</div>
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno">  258</span>                                        <span class="keyword">const</span> <span class="keywordtype">double</span> lastB,</div>
<div class="line"><a id="l00259" name="l00259"></a><span class="lineno">  259</span>                                        <span class="keyword">const</span> <span class="keywordtype">double</span> penultimateB,</div>
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno">  260</span>                                        <span class="keyword">const</span> <span class="keywordtype">double</span> s) <span class="keyword">const</span> <span class="keyword">noexcept</span></div>
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno">  261</span>        {</div>
<div class="line"><a id="l00262" name="l00262"></a><span class="lineno">  262</span>            <span class="keyword">const</span> <span class="keywordtype">double</span> DELTA = <a class="code hl_variable" href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">epsilon_</a> + <a class="code hl_function" href="namespacenc.html#a10ee4cd59b844c5dd99106a5dee12009">std::numeric_limits&lt;double&gt;::min</a>();</div>
<div class="line"><a id="l00263" name="l00263"></a><span class="lineno">  263</span> </div>
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno">  264</span>            <span class="keywordflow">return</span> (bisection &amp;&amp;</div>
<div class="line"><a id="l00265" name="l00265"></a><span class="lineno">  265</span>                    std::fabs(s - b) &gt;=</div>
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno">  266</span>                        0.5 * std::fabs(b - lastB)) || <span class="comment">// Bisection was used in last step but |s-b|&gt;=|b-lastB|/2 &lt;-</span></div>
<div class="line"><a id="l00267" name="l00267"></a><span class="lineno">  267</span>                                                       <span class="comment">// Interpolation step would be to rough, so still use bisection</span></div>
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno">  268</span>                   (!bisection &amp;&amp; std::fabs(s - b) &gt;=</div>
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno">  269</span>                                      0.5 * std::fabs(lastB - penultimateB)) || <span class="comment">// Interpolation was used in last step</span></div>
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno">  270</span>                                                                                <span class="comment">// but |s-b|&gt;=|lastB-penultimateB|/2 &lt;-</span></div>
<div class="line"><a id="l00271" name="l00271"></a><span class="lineno">  271</span>                                                                                <span class="comment">// Interpolation step would be to small</span></div>
<div class="line"><a id="l00272" name="l00272"></a><span class="lineno">  272</span>                   (bisection &amp;&amp;</div>
<div class="line"><a id="l00273" name="l00273"></a><span class="lineno">  273</span>                    std::fabs(b - lastB) &lt; DELTA) || <span class="comment">// If last iteration was using bisection and difference between</span></div>
<div class="line"><a id="l00274" name="l00274"></a><span class="lineno">  274</span>                                                     <span class="comment">// b and lastB is &lt; delta use bisection for next iteration</span></div>
<div class="line"><a id="l00275" name="l00275"></a><span class="lineno">  275</span>                   (!bisection &amp;&amp; std::fabs(lastB - penultimateB) &lt;</div>
<div class="line"><a id="l00276" name="l00276"></a><span class="lineno">  276</span>                                      DELTA); <span class="comment">// If last iteration was using interpolation but difference between</span></div>
<div class="line"><a id="l00277" name="l00277"></a><span class="lineno">  277</span>                                              <span class="comment">// lastB ond penultimateB is &lt; delta use biscetion for next iteration</span></div>
<div class="line"><a id="l00278" name="l00278"></a><span class="lineno">  278</span>        }</div>
<div class="line"><a id="l00279" name="l00279"></a><span class="lineno">  279</span>    };</div>
<div class="line"><a id="l00280" name="l00280"></a><span class="lineno">  280</span>} <span class="comment">// namespace nc::roots</span></div>
<div class="ttc" id="a_dtype_info_8hpp_html"><div class="ttname"><a href="_dtype_info_8hpp.html">DtypeInfo.hpp</a></div></div>
<div class="ttc" id="a_iteration_8hpp_html"><div class="ttname"><a href="_iteration_8hpp.html">Iteration.hpp</a></div></div>
<div class="ttc" id="a_types_8hpp_html"><div class="ttname"><a href="_types_8hpp.html">Types.hpp</a></div></div>
<div class="ttc" id="aclassnc_1_1_dtype_info_html_a2a3dc0ba2812411660219f61189d8aca"><div class="ttname"><a href="classnc_1_1_dtype_info.html#a2a3dc0ba2812411660219f61189d8aca">nc::DtypeInfo::max</a></div><div class="ttdeci">static constexpr dtype max() noexcept</div><div class="ttdef"><b>Definition:</b> DtypeInfo.hpp:110</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html">nc::roots::Brent</a></div><div class="ttdef"><b>Definition:</b> Brent.hpp:51</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_a1e9cf8f7be13c7bbb42a073ec9eb5369"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#a1e9cf8f7be13c7bbb42a073ec9eb5369">nc::roots::Brent::Brent</a></div><div class="ttdeci">Brent(const double epsilon, const uint32 maxNumIterations, std::function&lt; double(double)&gt; f) noexcept</div><div class="ttdef"><b>Definition:</b> Brent.hpp:74</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_a3853981ca1113723006b6627d96d378b"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#a3853981ca1113723006b6627d96d378b">nc::roots::Brent::solve</a></div><div class="ttdeci">double solve(double a, double b)</div><div class="ttdef"><b>Definition:</b> Brent.hpp:94</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_ade76ad260d82314f284ebacf885f6884"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#ade76ad260d82314f284ebacf885f6884">nc::roots::Brent::~Brent</a></div><div class="ttdeci">~Brent() override=default</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_brent_html_aecf6662d1b7128d38796cf4ab99143f4"><div class="ttname"><a href="classnc_1_1roots_1_1_brent.html#aecf6662d1b7128d38796cf4ab99143f4">nc::roots::Brent::Brent</a></div><div class="ttdeci">Brent(const double epsilon, std::function&lt; double(double)&gt; f) noexcept</div><div class="ttdef"><b>Definition:</b> Brent.hpp:60</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html">nc::roots::Iteration</a></div><div class="ttdoc">ABC for iteration classes to derive from.</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:46</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a2d7285a81c033d56ce8283b6dbfca136"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a2d7285a81c033d56ce8283b6dbfca136">nc::roots::Iteration::Iteration</a></div><div class="ttdeci">Iteration(double epsilon) noexcept</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:54</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a5eafe219bb90f82da4ece84f012a411a"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a5eafe219bb90f82da4ece84f012a411a">nc::roots::Iteration::epsilon_</a></div><div class="ttdeci">const double epsilon_</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:114</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_a85e79a4794bc3a6ac6bc3564956737a2"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#a85e79a4794bc3a6ac6bc3564956737a2">nc::roots::Iteration::resetNumberOfIterations</a></div><div class="ttdeci">void resetNumberOfIterations() noexcept</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:94</div></div>
<div class="ttc" id="aclassnc_1_1roots_1_1_iteration_html_ad0262a1a694e734ebc154c77f010bcff"><div class="ttname"><a href="classnc_1_1roots_1_1_iteration.html#ad0262a1a694e734ebc154c77f010bcff">nc::roots::Iteration::incrementNumberOfIterations</a></div><div class="ttdeci">void incrementNumberOfIterations()</div><div class="ttdef"><b>Definition:</b> Iteration.hpp:103</div></div>
<div class="ttc" id="aessentially_equal_8hpp_html"><div class="ttname"><a href="essentially_equal_8hpp.html">essentiallyEqual.hpp</a></div></div>
<div class="ttc" id="anamespacenc_1_1random_1_1detail_html_af5bfd54c6d5d0ad7e16e6e532b0dfb2e"><div class="ttname"><a href="namespacenc_1_1random_1_1detail.html#af5bfd54c6d5d0ad7e16e6e532b0dfb2e">nc::random::detail::f</a></div><div class="ttdeci">dtype f(GeneratorType &amp;generator, dtype inDofN, dtype inDofD)</div><div class="ttdef"><b>Definition:</b> f.hpp:56</div></div>
<div class="ttc" id="anamespacenc_1_1roots_html"><div class="ttname"><a href="namespacenc_1_1roots.html">nc::roots</a></div><div class="ttdef"><b>Definition:</b> Bisection.hpp:43</div></div>
<div class="ttc" id="anamespacenc_1_1utils_html_a963b90e7c9a3b057a924298750ddf74c"><div class="ttname"><a href="namespacenc_1_1utils.html#a963b90e7c9a3b057a924298750ddf74c">nc::utils::essentiallyEqual</a></div><div class="ttdeci">bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept</div><div class="ttdef"><b>Definition:</b> essentiallyEqual.hpp:49</div></div>
<div class="ttc" id="anamespacenc_html_a10ee4cd59b844c5dd99106a5dee12009"><div class="ttname"><a href="namespacenc.html#a10ee4cd59b844c5dd99106a5dee12009">nc::min</a></div><div class="ttdeci">NdArray&lt; dtype &gt; min(const NdArray&lt; dtype &gt; &amp;inArray, Axis inAxis=Axis::NONE)</div><div class="ttdef"><b>Definition:</b> min.hpp:44</div></div>
<div class="ttc" id="anamespacenc_html_a39da0502565b913855379ea1439047e1"><div class="ttname"><a href="namespacenc.html#a39da0502565b913855379ea1439047e1">nc::swap</a></div><div class="ttdeci">void swap(NdArray&lt; dtype &gt; &amp;inArray1, NdArray&lt; dtype &gt; &amp;inArray2) noexcept</div><div class="ttdef"><b>Definition:</b> swap.hpp:42</div></div>
<div class="ttc" id="anamespacenc_html_af0f49663fb63332596e2e6327009d581"><div class="ttname"><a href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a></div><div class="ttdeci">std::uint32_t uint32</div><div class="ttdef"><b>Definition:</b> Types.hpp:40</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_34171bd951b13a53aa9f237277a18e40.html">NumCpp</a></li><li class="navelem"><a class="el" href="dir_22368e90b3593b912515c50bf54c969c.html">Roots</a></li><li class="navelem"><a class="el" href="_brent_8hpp.html">Brent.hpp</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
  </ul>
</div>
</body>
</html>
